package com.itheima.mm.controller;


import com.itheima.mm.dto.CourseDTO;
import com.itheima.mm.entity.CoursePageQueryParams;
import com.itheima.mm.entity.PageResult;
import com.itheima.mm.entity.QueryPageBean;
import com.itheima.mm.entity.Result;
import com.itheima.mm.pojo.Course;
import com.itheima.mm.service.CourseService;
import com.itheima.mm.vo.CourseAddVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description CourseController
 * @Author mylee
 * @Date 2023-09-26
 */
@RestController
@Slf4j
@Api(tags = "学科管理接口")
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    /**
     * 新增学科
     *
     * @return
     * @param: courseAllVO
     **/
    @ApiOperation("新增学科")
    @PostMapping("/add.do")
    public Result add(@RequestBody CourseAddVO courseAddVO) {
        log.info("新增学科:{}", courseAddVO);
        courseService.add(courseAddVO);
        return Result.success();
    }

    /**
     * 学科列表
     *
     * @return
     * @param: queryPageBean
     **/
    @ApiOperation("学科列表")
    @PostMapping("/findListByPage.do")
    public Result<PageResult<Course>> pageQuery(@RequestBody QueryPageBean<CoursePageQueryParams> queryPageBean) {
        log.info("学科列表：{}", queryPageBean);
        PageResult<Course> pageResult = courseService.pageQuery(queryPageBean);
        return Result.success(pageResult);
    }

    /**
     * 学科更新
     *
     * @return
     * @param: courseDTO
     **/
    @ApiOperation("学科更新")
    @PostMapping("/update.do")
    public Result update(@RequestBody CourseDTO courseDTO) {
        log.info("学科更新：{}", courseDTO);
        courseService.update(courseDTO);
        return Result.success();
    }

    /**
     * 删除学科
     *
     * @return
     * @param: courseId
     **/
    @ApiOperation("删除学科")
    @GetMapping("/delete.do")
    public Result delete( Integer courseId) {
        log.info("删除学科；{}", courseId);
        courseService.deleteByCourse(courseId);
        return Result.success();
    }

}
